<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html lang="zh" class="no-js">
<head>
<title>后台</title>
<meta charset="UTF-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet"
	href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="//cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- Jqueryform -->
<script src="<c:url value="/resources/js/jquery.form.js" />"></script>
</head>
<body style="background-color: rgb(245, 245, 245);">

	<div class="container"
		style="box-shadow: 2px 2px 3px rgba(40, 61, 90, 0.22); background-color: white; margin-top: 25px">

		<h2 class="text-center">信息录入</h2>

		<form class="form-horizontal" style="margin-top: 30px" method="post" onsubmit="return check();"
			action="<c:url value='/Express/doAddRecord' ></c:url>">
           <div  id="nu-space" >
			<div class="form-group">
				<label class="control-label col-xs-2">单号</label>
				<div class="col-xs-10">
					<input name="nus" type="text" class="form-control nu" 
						placeholder="单号">
				</div>
			</div>
			</div>
			
			
			

			
			<div class="form-group">
				<label class="control-label col-xs-2">信息</label>
				<div class="col-xs-10">
					<textarea name="content" id="content" class="form-control" 
						placeholder="信息"></textarea>
				</div>
			</div>

			<div class="form-group">
				<div class="col-xs-offset-2 col-xs-10">
					<input type="submit" class="btn btn-primary" value="录入" />
					
					<a id="import" class="btn btn-primary">导入</a>
				</div>
			</div>
		</form>
		
		<form id="importExcelForm" action="<c:url value='/Express/importExcel' ></c:url>" method="post" enctype="multipart/form-data"  >
		<input id="file" name="file" type="file" style="display: none" />
		</form>

	</div>
	<script>
	
	function check(){
		var flag=true;
		$.each($(".nu"),function(k,v){
			if($(v).val()==null||$(v).val()=="")
				{alert("单号不能为空,请检查");flag=false;return false;}
	
		});
		
		if($("#content").val()=="")
			{alert("信息不能为空");flag=false;}
		
		return flag;
		
	}
	
		$("#import").bind("click", function() {
			$("#file").click();
		});

		$("#file").bind("change", function() {
			$("#importExcelForm").submit();
		});
		
		$('#importExcelForm').submit(function() {
			// 提交表单
			
			$(this).ajaxSubmit(function(message) {
				
				if(message==null)
					alert("导入失败");
				var html="";
				
				$.each(message,function(k,v){
					
					
					if(k%2==0)
						{
						html+='<div class="form-group">'+
							'<label class="control-label col-xs-2"></label>';}
					
					html+='<div class="col-xs-5">'+
							'<input name="nus" type="text" class="form-control nu"  '+
							' value='+v+' >'+
					'</div>';
					if(k%2==1)
						{
							html+='</div>';
							}
				});
				$("#nu-space").append(html);
			
			});
			// 为了防止普通浏览器进行表单提交和产生页面导航（防止页面刷新？）返回false
			return false;
		});
		
	</script>

</body>
</html>